package net.chrisrichardson.ec2deployer.core

class AwsUtilities {

    EC2Server host
    private boolean initialized

    AwsUtilities(EC2Server host) {
        this.host = host
    }

    void initializeAwsSecretFile() {
      if (!initialized) {
          host.ssh("rm -f .awssecret ; cat > .awssecret; chmod 0600 .awssecret", "${host.awsProperties.accessKey} ${host.awsProperties.secretKey}")
      }
      initialized  = true;

    }

    void s3get(String s3Path, String localPath) {
        initializeAwsSecretFile()
        host.ssh("s3get $s3Path $localPath")
    }

    void s3put(String s3Path, String localPath) {
        initializeAwsSecretFile()
        host.ssh("s3put $s3Path $localPath")
    }



    void mkdir(String bucketName) {
        initializeAwsSecretFile()
        host.ssh("aws mkdir $bucketName")
    }
}